package org.example;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.function.Function;

public class Function_Demo4 {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list, "张三,13", "张守元,14", "王行之,15", "张由心,16");
        //                                方法引用(构造方法)       引用数组构造方法
        Student[] arr1 = list.stream().map(Student::new).toArray(Student[]::new);
        System.out.println(Arrays.toString(arr1));
        System.out.println("----------------1");
        //将数组转换为集合
        ArrayList<Student> list1 = new ArrayList<>(Arrays.asList(arr1));
        list1.add(new Student("zhangsan",13));
        list1.add(new Student("lisi",14));
        list1.add(new Student("wangwu",15));
        list1.add(new Student("zhaoliu",16));
        String[] arr2 = list1.stream().map(Student::getName).toArray(String[]::new);
        System.out.println(Arrays.toString(arr2));
        System.out.println("----------------2");
        list1.stream().map(new Function<Student, String>() {
            @Override
            public String apply(Student student) {
                return student.getName();
            }
        }).toArray(String[]::new);
        System.out.println(Arrays.toString(arr2));
    }
}
